/*  Game/Army Editor for yALB - Yet Another List Builder (roster Editor for Wargames/tabletop games).
    Copyright (C) 2008-2012  Daniel Ricardo Castro Alvarado

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.*/

#ifndef PROPERTYFORM_H
#define PROPERTYFORM_H

#include <QDialog>
#include <QTableWidget>
#include "../other/gameStructs.h"

namespace Ui {
    class PropertyForm;
}

class PropertyForm : public QDialog
{
    Q_OBJECT

public:
    explicit PropertyForm(QWidget *parent = 0);
    ~PropertyForm();
    void setPropertyValue(const QString& key, const QString& value);
    QHash<QString, QString> getProperties() const;
    void savePropertyValues();

public slots:
    void addProperty(const GameProperty& property, const QString& key);
    void updateProperty(const QString& oldKey, const GameProperty& newProperty,
                        const QString& newKey);
    void removeProperty(const QString& key);
    void clearAllValues();
    void clearAll();
    void accept();

protected:
    void changeEvent(QEvent *event);

private:
    Ui::PropertyForm *ui;
    QHash<QString, int> keyIndex;
    QHash<QString, QString> properties;

    int findRowWithKey(const QString& key);
    void rebuildIndex();
};

#endif // PROPERTYFORM_H
